@echo off
echo "==>TAO_ROOT=%TAO_ROOT%"

set PROJECT_PATH="%TAO_ROOT%/orbsvcs/tests/FT_App"

cd %PROJECT_PATH%

@echo off
setlocal

:: 定义要删除的文件列表
set "files=*.ior"

:: 删除文件
for %%f in (%files%) do (
    if exist "%%f" (
        echo Deleting %%f...
        del "%%f"
        if not errorlevel 1 (
            echo Deleted %%f successfully.
        ) else (
            echo Error deleting %%f.
        )
    ) else (
        echo %%f does not exist. Skipping.
    )
)


@echo off
:menu
echo input(1 use rm, 2 not use rm):
set /p choice=

if "%choice%"=="1" goto use_rm
if "%choice%"=="2" goto not_use_rm

echo invalid input!
goto menu

:use_rm
@REM 启动命名服务
echo "==>Start tao_cosnaming"
start "tao_cosnaming" cmd /k "%TAO_ROOT%/orbsvcs/Naming_Service/tao_cosnaming -ORBdebuglevel -o %PROJECT_PATH%/ns.ior -m 1"
timeout /t 4

@REM 启动副本管理器
echo "==>Start tao_ft_replicationmanager"
start "tao_ft_replicationmanager" cmd /k "%TAO_ROOT%/orbsvcs/FT_ReplicationManager/tao_ft_replicationmanager -o %PROJECT_PATH%/rm.ior -ORBEndpoint iiop://OMEN_2023:18435 -n ReplicationManager"
timeout /t 4


echo "==>Start ft_replica1"
start "ft_replica1" cmd /k "ft_replica -o %PROJECT_PATH%/factory1.ior -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -l shire -i hobbit -q -p %PROJECT_PATH%/persistent.dat"
timeout /t 4

echo "==>Start ft_replica2"
start "ft_replica2" cmd /k "ft_replica -o %PROJECT_PATH%/factory2.ior -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -l bree -i hobbit -i elf -i human -q -u -p %PROJECT_PATH%/persistent.dat"
timeout /t 4

echo "==>Start ft_replica3"
start "ft_replica3" cmd /k "ft_replica -o %PROJECT_PATH%/factory3.ior -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -l rivendell -i elf -q -u -p %PROJECT_PATH%/persistent.dat"
timeout /t 4

@REM 创建对象组 Create object groups,生成副本对象引用文件 
echo "==>Start ft_create"
start "ft_create" cmd /k "ft_create -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -n -r hobbit -r elf -r hobbit -u human -i"
timeout /t 10

@REM ========== 启动客户端 -f 指定对象组ior文件  共 3个 场景
echo "==> Start ft_client hobbit_shire_0"
start "ft_client hobbit_shire_0" cmd /k "ft_client -f file://%PROJECT_PATH%/hobbit_shire_0.ior -f file://%PROJECT_PATH%/hobbit_bree_0.ior -c testscript"
timeout /t 20

@REM echo "==>Start ft_client elf_bree_1"
@REM start "ft_client elf_bree_1" cmd /k "ft_client -f file://%PROJECT_PATH%/elf_bree_1.ior -f file://%PROJECT_PATH%/elf_rivendell_0.ior -c testscript"
@REM timeout /t 20

@REM echo "==>Start ft_client hobbit_shire_1"
@REM start "ft_client hobbit_shire_1" cmd /k "ft_client -f file://%PROJECT_PATH%/hobbit_shire_1.ior -f file://%PROJECT_PATH%/hobbit_bree_2.ior -c testscript"

@REM timeout /t 60
@REM @REM 关闭副本管理器
@REM echo "==>Start replmgr_controller"
@REM start "replmgr_controller" cmd /k "replmgr_controller -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -x"
@REM timeout /t 15

goto end


:not_use_rm
@REM ------不使用副本管理器-----
echo "==>Start ft_registry 工厂注册表"
start "ft_registry" cmd /k "ft_registry -o %PROJECT_PATH%/registry.ior -q"
timeout /t 4


start "ft_replica1" cmd /k "ft_replica -o %PROJECT_PATH%/factory1.ior -f file://%PROJECT_PATH%/registry.ior -l shire -i hobbit -q -p %PROJECT_PATH%/persistent.dat"
timeout /t 4

start "ft_replica2" cmd /k "ft_replica -o %PROJECT_PATH%/factory2.ior -f file://%PROJECT_PATH%/registry.ior -l bree -i hobbit -i elf -i human -q -u -p %PROJECT_PATH%/persistent.dat"
timeout /t 4

start "ft_replica3" cmd /k "ft_replica -o %PROJECT_PATH%/factory3.ior -f file://%PROJECT_PATH%/registry.ior -l rivendell -i elf -q -u -p %PROJECT_PATH%/persistent.dat"
timeout /t 4

@REM 创建对象组 Create object groups, 共3个场景
start "ft_create" cmd /k "ft_create -f file://%PROJECT_PATH%/registry.ior -n -r hobbit -r elf -r hobbit -u human -i"
timeout /t 15

@REM -f hobbit_shire_0.ior 副本, hobbit_bree_0.ior 副本
@REM start "ft_client hobbit_shire_0" cmd /k "ft_client -f file://%PROJECT_PATH%/hobbit_shire_0.ior -f file://%PROJECT_PATH%/hobbit_bree_0.ior -c testscript"
@REM timeout /t 20

@REM start "ft_client elf_bree_1" cmd /k "ft_client -f file://%PROJECT_PATH%/elf_bree_1.ior -f file://%PROJECT_PATH%/elf_rivendell_0.ior -c testscript"
@REM timeout /t 20

@REM start "ft_client hobbit_shire_1" cmd /k "ft_client -f file://%PROJECT_PATH%/hobbit_shire_1.ior -f file://%PROJECT_PATH%/hobbit_bree_2.ior -c testscript"
@REM timeout /t 20

@REM 关闭副本管理器
start "replmgr_controller" cmd /k "replmgr_controller -f file://%PROJECT_PATH%/registry.ior -x"
timeout /t 4
goto end


:end
echo -----end
@echo off


@REM start %TAO_ROOT%/orbsvcs/FT_ReplicationManager/tao_ft_replicationmanager -o %PROJECT_PATH%/rm.ior -ORBEndpoint iiop://OMEN_2023:18435

@REM ------使用副本管理器-----

@REM start ./ft_registry -o %PROJECT_PATH%/registry.ior -q
@REM start ./ft_replica -o %PROJECT_PATH%/factory1.ior -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -l shire -i hobbit -q -p %PROJECT_PATH%/persistent.dat
@REM start ./ft_replica -o %PROJECT_PATH%/factory2.ior -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -l bree -i hobbit -i elf -i human -q -u -p %PROJECT_PATH%/persistent.dat
@REM start ./ft_replica -o %PROJECT_PATH%/factory3.ior -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -l rivendell -i elf -q -u -p %PROJECT_PATH%/persistent.dat
@REM start ./ft_create -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -n -r hobbit -r elf -r hobbit -u human -i
@REM start ./replmgr_controller -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -x


@REM ------不使用副本管理器------
@REM start ./ft_create -f file://%PROJECT_PATH%/registry.ior -n -r hobbit -r elf -r hobbit -u human -i
@REM start ./ft_replica -o %PROJECT_PATH%/factory1.ior -f file://%PROJECT_PATH%/registry.ior -l shire -i hobbit -q -p %PROJECT_PATH%/persistent.dat
@REM start ./ft_replica -o %PROJECT_PATH%/factory2.ior -f file://%PROJECT_PATH%/registry.ior -l bree -i hobbit -i elf -i human -q -u -p %PROJECT_PATH%/persistent.dat
@REM start ./ft_replica -o %PROJECT_PATH%/factory3.ior -f file://%PROJECT_PATH%/registry.ior -l rivendell -i elf -q -u -p %PROJECT_PATH%/persistent.dat
@REM start ./replmgr_controller -f file://%PROJECT_PATH%/registry.ior -x

@REM ------client------
@REM start ./ft_client -f file://%PROJECT_PATH%/hobbit_shire_0.ior -f file://%PROJECT_PATH%/hobbit_bree_0.ior -c testscript
@REM start ./ft_client -f file://%PROJECT_PATH%/elf_bree_1.ior -f file://%PROJECT_PATH%/elf_rivendell_0.ior -c testscript
@REM start ./ft_client -f file://%PROJECT_PATH%/hobbit_shire_1.ior -f file://%PROJECT_PATH%/hobbit_bree_2.ior -c testscript




@REM 原始指令
@REM start E:\_proj\_opendds\ACE_wrappers\TAO/orbsvcs/FT_ReplicationManager/tao_ft_replicationmanager -o E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\rm.ior -ORBEndpoint iiop://OMEN_2023:18435


@REM ------使用副本管理器-----

@REM start ./replmgr_controller -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -x
@REM start ./ft_registry -o E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\registry.ior -q
@REM start ./ft_replica -o E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\factory1.ior -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -l shire -i hobbit -q -p E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\persistent.dat
@REM start ./ft_replica -o E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\factory2.ior -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -l bree -i hobbit -i elf -i human -q -u -p E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\persistent.dat
@REM start ./ft_replica -o E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\factory3.ior -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -l rivendell -i elf -q -u -p E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\persistent.dat
@REM start ./ft_create -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:18435/ReplicationManager -n -r hobbit -r elf -r hobbit -u human -i


@REM ------不使用副本管理器------
@REM start ./replmgr_controller -f file://E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\registry.ior -x
@REM start ./ft_replica -o E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\factory1.ior -f file://E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\registry.ior -l shire -i hobbit -q -p E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\persistent.dat
@REM start ./ft_replica -o E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\factory2.ior -f file://E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\registry.ior -l bree -i hobbit -i elf -i human -q -u -p E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\persistent.dat
@REM start ./ft_replica -o E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\factory3.ior -f file://E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\registry.ior -l rivendell -i elf -q -u -p E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\persistent.dat
@REM start ./ft_create -f file://E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\registry.ior -n -r hobbit -r elf -r hobbit -u human -i


@REM ------client------
@REM start ./ft_client -f file://E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\hobbit_shire_0.ior -f file://E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\hobbit_bree_0.ior -c testscript
@REM start ./ft_client -f file://E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\elf_bree_1.ior -f file://E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\elf_rivendell_0.ior -c testscript
@REM start ./ft_client -f file://E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\hobbit_shire_1.ior -f file://E:\_proj\_opendds\ACE_wrappers\TAO\orbsvcs\tests\FT_App\hobbit_bree_2.ior -c testscript